﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.ComponentModel;

namespace DataVisualization
{
    public class InformationSet
    {
        private string fileName;
        private bool isLoaded;
        private BindingList<string> header;
        private BindingList<VisualizationRow> row;

        public InformationSet()
        {
            isLoaded = false;
            fileName = "";
            header = new BindingList<string>();
            row = new BindingList<VisualizationRow>();
        }
        public void Clear()
        {
            isLoaded = false;
            fileName = "";
            header.Clear();
            row.Clear();
            header = new BindingList<string>();
            row = new BindingList<VisualizationRow>();
        }
        public void readFile()
        {
            try
            {
                System.IO.StreamReader reader = new System.IO.StreamReader(fileName);
                foreach (string column in reader.ReadLine().Split(','))
                {
                    header.Add(column);
                }
                while (!reader.EndOfStream)
                {
                    row.Add(new VisualizationRow(reader.ReadLine().Split(',')));
                }
                reader.Close();
                isLoaded = true;
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message + ex.StackTrace);
                //exception eater
            }
        }

        public BindingList<string> Header
        {
            get { return header; }
            set { header = value; }
        }

        public string FileName
        {
            get { return fileName; }
            set { fileName = value; }
        }

        public BindingList<VisualizationRow> Row
        {
            get { return row; }
            set { row = value; }
        }

        public bool IsLoaded
        {
            get { return isLoaded; }
            set { isLoaded = value; }
        }
    }

    public class VisualizationRow
    {
        private BindingList<string> items;

        public BindingList<string> Items
        {
            get { return items; }
            set { items = value; }
        }

        public VisualizationRow()
        {
            items = new BindingList<string>();
        }
        public VisualizationRow(string[] row)
        {
            items = new BindingList<string>();
            foreach (string dataItem in row)
            {
                items.Add(dataItem);
            }
        }
        public void addRow(string[] newRow)
        {
            foreach (string dataItem in newRow)
            {
                items.Add(dataItem);
            }
        }
        public void Clear()
        {
            items.Clear();
        }
    }
}
